package com.mc.web.controller.fil;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mc.common.annotation.Log;
import com.mc.common.core.controller.BaseController;
import com.mc.common.core.domain.AjaxResult;
import com.mc.common.enums.BusinessType;
import com.mc.fil.domain.FilPhenologicalPhase;
import com.mc.fil.service.IFilPhenologicalPhaseService;
import com.mc.common.utils.poi.ExcelUtil;
import com.mc.common.core.page.TableDataInfo;

/**
 * 物候期 Controller
 *
 * @author mc
 * @date 2021-04-14
 */
@RestController
@RequestMapping("/fil/phase")
public class FilPhenologicalPhaseController extends BaseController
{
    @Autowired
    private IFilPhenologicalPhaseService filPhenologicalPhaseService;

    /**
     * 查询物候期 列表
     */
    @PreAuthorize("@ss.hasPermi('fil:phase:list')")
    @GetMapping("/list")
    public TableDataInfo list(FilPhenologicalPhase filPhenologicalPhase)
    {
        startPage();
        List<FilPhenologicalPhase> list = filPhenologicalPhaseService.selectFilPhenologicalPhaseList(filPhenologicalPhase);
        return getDataTable(list);
    }

    /**
     * 导出物候期 列表
     */
    @PreAuthorize("@ss.hasPermi('fil:phase:export')")
    @Log(title = "物候期 ", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FilPhenologicalPhase filPhenologicalPhase)
    {
        List<FilPhenologicalPhase> list = filPhenologicalPhaseService.selectFilPhenologicalPhaseList(filPhenologicalPhase);
        ExcelUtil<FilPhenologicalPhase> util = new ExcelUtil<FilPhenologicalPhase>(FilPhenologicalPhase.class);
        return util.exportExcel(list, "phase");
    }

//    /**
//     * 获取物候期 详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('fil:phase:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id)
//    {
//        return AjaxResult.success(filPhenologicalPhaseService.selectFilPhenologicalPhaseById(id));
//    }

    /**
     * 新增物候期
     */
    @PreAuthorize("@ss.hasPermi('fil:phase:add')")
    @Log(title = "物候期 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FilPhenologicalPhase filPhenologicalPhase)

    {
        FilPhenologicalPhase phenologicalPhase = filPhenologicalPhaseService.selectFilPhenologicalPhaseById(filPhenologicalPhase.getFilId());
        if(phenologicalPhase != null){
            filPhenologicalPhase.setId(phenologicalPhase.getId());
            return toAjax(filPhenologicalPhaseService.updateFilPhenologicalPhase(filPhenologicalPhase));
        }else{
            return toAjax(filPhenologicalPhaseService.insertFilPhenologicalPhase(filPhenologicalPhase));
        }

    }
    /**
     * 修改物候期
     */
    @PreAuthorize("@ss.hasPermi('fil:phase:edit')")
    @Log(title = "物候期 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FilPhenologicalPhase filPhenologicalPhase)
    {
        return toAjax(filPhenologicalPhaseService.updateFilPhenologicalPhase(filPhenologicalPhase));
    }

}